﻿<div class="row align-items-center" style="text-align:center">
    总数： @PagesCount 每行显示
    <select class="form-select form-select-sm" aria-label=".form-select-sm example" style="width:7%" @onchange="onChanges">
        @foreach (var op in list)
        {
            @if (op == PagesSize)
            {
                <option value="@op" selected>@op</option>
            }
            else

            {
                <option value="@op">@op</option>
            }
        }
    </select>

    <ul class="pagination justify-content-center">
        <li class="page-item @(PageNumber == 1 ? "disabled" : "")">
            <a class="page-link" @onclick="() => HandlePageChange(PageNumber - 1)" tabindex="-1" aria-disabled="true">上一页</a>
        </li>
        @for (int pageNumber = 1; pageNumber <= TotalPages; pageNumber++)
        {
            if (Math.Abs(pageNumber - PageNumber) < 3 || pageNumber == 1 || pageNumber == TotalPages)
            {
                int currentPageNumber = pageNumber;
                <li class="page-item @(pageNumber == PageNumber ? "active" : "")">
                    <a class="page-link" @onclick="() => HandlePageChange(currentPageNumber)">@pageNumber</a>
                </li>
            }
        }
        <li class="page-item @(PageNumber == TotalPages ? "disabled" : "")">
            <a class="page-link" @onclick="() => HandlePageChange(PageNumber + 1)">下一页</a>
        </li>
    </ul>
</div>
@code {
    [Parameter]
    public int PagesCount { get; set; } = 20;
    [Parameter]
    public int PagesSize { get; set; } = 20;
    [Parameter]
    public int PageNumber { get; set; } = 1;
    public int TotalPages => (int)Math.Ceiling((double)PagesCount / PagesSize);
    public List<int> list { get; set; } = new List<int>()
    {10,20,30,40,50,60,80,90,100};
    [Parameter]
    public EventCallback<int> PageChanged { get; set; }
    [Parameter]
    public EventCallback<ChangeEventArgs> onChange { get; set; }


    private async Task HandlePageChange(int pageNumber)
    {
        if (pageNumber >= 1 && pageNumber <= TotalPages)
        {
            await PageChanged.InvokeAsync(pageNumber);
        }
    }
    private async Task onChanges(ChangeEventArgs e)
    {
        await onChange.InvokeAsync(e);

    }
}
